<!--
+----------------------------------------------------------------------
| 友得云客  - 开启房产营销新纪元
+----------------------------------------------------------------------
| Copyright (c) 2019~2023 优得（西安）信息科技有限公司版权所有
+----------------------------------------------------------------------
| Licensed 友得云客不是自由软件 未经允许不可移除相关版权
+----------------------------------------------------------------------
| Author: www.youdeyunke.com
+----------------------------------------------------------------------
-->
<template>
    <div v-loading="loading">
        <el-form v-if="item" :model="item" size="small" label-position="right" label-width="120px">
            <el-form-item label="分组名称">
                <el-input style="width: 220px" v-model="item.name" placeholder="2~5个字"></el-input>
            </el-form-item>

            <el-form-item label="备注">
                <el-input style="width: 400px" v-model="item.remark" placeholder="备注说明"></el-input>
                <div>备注信息仅对管理员显示</div>
            </el-form-item>

            <el-form-item size="large">
                <el-button type="primary" @click="submitHandle">保存</el-button>
                <el-button type="text" @click="$emit('cancle')">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import { updateUserGroup, createUserGroup } from "@/api/user";
export default {
    data () {
        return {
            loading: false,
        };
    },
    props: {
        item: { type: Object, default: null },
    },

    mounted: function () { },

    computed: {},

    methods: {
        validate: function (data) {
            if (data.name.length <= 1 || data.name.length > 10) {
                this.$message.error("分组名不能少于2个字，不能多于10个字");
                return false;
            }
            return true;
        },
        submitHandle: function () {
            // 创建或者修改
            var data = this.item;
            var isok = this.validate(data);
            if (!isok) {
                return;
            }
            if (data.id) {
                updateUserGroup(data).then((resp) => {
                    this.submitCallback(resp);
                });
            } else {
                createUserGroup(data).then((resp) => {
                    this.submitCallback(resp);
                });
            }
        },

        submitCallback: function (resp) {
            this.loading = false;
            if (resp.status === 0) {
                this.$emit("success");
            }
        },
    },
};
</script>

<style scoped></style>
